Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@babel/plugin-syntax-do-expressions
Advanced tools
@babel/plugin-syntax-do-expressions is a Babel plugin that allows you to use the 'do' expression syntax in your JavaScript code. This syntax enables you to use block statements as expressions, which can be useful for complex logic that needs to return a value.
Basic do expression
This feature allows you to use a block statement as an expression. The block can contain multiple statements, and the value of the last statement is returned as the value of the 'do' expression.
const result = do {
if (x > 10) {
'greater';
} else {
'lesser';
}
};
Complex logic in do expression
This feature allows you to include more complex logic within the 'do' expression, such as variable declarations and multiple conditional statements.
const result = do {
let temp = x * 2;
if (temp > 20) {
'large';
} else {
'small';
}
};
This Babel plugin allows you to use the pipeline operator (|>) in your JavaScript code. The pipeline operator enables a more readable and functional approach to chaining functions. Unlike 'do' expressions, which are used for block statements, the pipeline operator is used for function composition.
This Babel plugin allows you to use optional chaining (?.) in your JavaScript code. Optional chaining provides a way to simplify accessing deeply nested properties without having to explicitly check for the existence of each level. While 'do' expressions are used for block statements, optional chaining is used for safely accessing object properties.
Allow parsing of do expressions
See our website @babel/plugin-syntax-do-expressions for more information.
Using npm:
npm install --save-dev @babel/plugin-syntax-do-expressions
or using yarn:
yarn add @babel/plugin-syntax-do-expressions --dev
FAQs
Allow parsing of do expressions
We found that @babel/plugin-syntax-do-expressions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.